package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallMoneyLogMapper;
import org.linlinjava.litemall.db.domain.LitemallMoneyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallMoneyLogService {

@Resource
@Autowired
private LitemallMoneyLogMapper   litemallMoneyLogMapper;


    /**
     *
     * @param pay 支出
     * @param income 收入
     * @param remarks  备注
     * @param userId  用户
     * @param type   金额类型 FSP sun 等等
     * @param tuijian  推荐人 获取的途径 ： 1 直推  2 间推 3 商户 4 本人 5管理
     * @param remain  余额
     * @param orderid   订单
     * @return
     */
    public  int   insertMoney(double   pay  ,double   income,String   remarks,int  userId,String   type ,int tuijian,double remain,int  orderid){
    LitemallMoneyLog litemallMoneyLog=new LitemallMoneyLog();

    litemallMoneyLog.setPay(pay);
    litemallMoneyLog.setIncome(income);
    litemallMoneyLog.setRemarks(remarks);
    litemallMoneyLog.setUserId(userId);
    litemallMoneyLog.setType(type);
    litemallMoneyLog.setTuijian(tuijian);
    litemallMoneyLog.setRemain(remain);
litemallMoneyLog.setOrderid(orderid);
    return litemallMoneyLogMapper.insertMoney(litemallMoneyLog);
}

    public  int   insertMoneyByadmin(double   pay  ,double   income,String   remarks,int  userId,String   type ,String admin,double remain){
        LitemallMoneyLog litemallMoneyLog=new LitemallMoneyLog();

        litemallMoneyLog.setPay(pay);
        litemallMoneyLog.setIncome(income);
        litemallMoneyLog.setRemarks(remarks);
        litemallMoneyLog.setUserId(userId);
        litemallMoneyLog.setType(type);
        litemallMoneyLog.setAdmin(admin);
        litemallMoneyLog.setRemain(remain);

        return litemallMoneyLogMapper.insertMoneyByAdmin(litemallMoneyLog);
    }


    public List<LitemallMoneyLog> querySelective(Integer page, Integer limit, String sort, String order, String starttime, String lasttime) {

    int start = (page-1)*limit;


    return litemallMoneyLogMapper.querySelective(start,limit,sort,order,starttime,lasttime);


    }

    public List<LitemallMoneyLog> findById(Integer userId, Integer page, Integer limit, String sort, String order,String type) {



        Integer start = (page-1)*limit;
        Integer end = limit;

        return litemallMoneyLogMapper.selectByPrimaryKey(userId,start,end,sort,order,type);
    }


    public List<LitemallMoneyLog> findAllById(Integer userId, String type) {
        return litemallMoneyLogMapper.selectAllByPrimaryKey(userId,type);
    }
}
